package DailySheet.Activity;

import hepengfei.SQL.SQLInterface;

import java.util.ArrayList;
import java.util.List;

import DailySheet.CourseManage.Profile;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class AllprofileAct extends Activity{

	private ListView myList;
	int qzx;
	SQLInterface myInter=new SQLInterface(AllprofileAct.this);
	ArrayList<Profile> myPro=new ArrayList<Profile>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.allprofile);
		Intent intent=getIntent();
		qzx=intent.getIntExtra("qzx", 0);
		myList=(ListView)findViewById(R.id.allprofileList);
		myPro=myInter.FindAllProfile();
		if(qzx == 0)
		{
			myList.setOnItemClickListener(new listLisener2());
		}
		else 
		{
			myList.setOnItemClickListener(new listLisener1());
		}
		List<String>ProName = new ArrayList<String>();
		for(int i=0;i<myPro.size();i++)
		{
			ProName.add(myPro.get(i).getPName());
	
		}
		ArrayAdapter<String> mArrayAda=new ArrayAdapter<String>(AllprofileAct.this, android.R.layout.simple_list_item_1, ProName);
		myList.setAdapter(mArrayAda);
		
	}
	class listLisener1 implements OnItemClickListener
	{

		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			String hus=null;
			hus=(String)myList.getItemAtPosition(arg2);
			SharedPreferences userInfo = getSharedPreferences("user_info", 0);
			userInfo.edit().putInt("DefaultProfile", arg2).commit();
			Intent intent =new Intent();
			intent.putExtra("hpf", hus);
			intent.setClass(AllprofileAct.this, ProfileChoice.class);
			startActivity(intent);
		}
		
	}
	class listLisener2 implements OnItemClickListener
	{

		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Intent intent=new Intent();
			String hus=null;
			hus=(String)myList.getItemAtPosition(arg2);
			intent.putExtra("zhq", 0);
			intent.putExtra("hpf",hus);
			intent.setClass(AllprofileAct.this, ProfileMainAct.class);
			startActivity(intent);
		}
		
	}


}
